package lxs.swift.instance.action;

import lxs.swift.instance.StructInstance;

import java.util.function.Function;

public class LongAction<Key> extends Action<Key, Long> {

    public LongAction(StructInstance<Key> instance, Function<Object, Long> convertor) {
        super(instance, convertor);
    }

    public void acc(Key key, long num) {
        Long value = getOr(key, 0L);
        set(key, value + num);
    }

    public void mul(Key key, long num) {
        Long value = getOr(key, 0L);
        set(key, value * num);
    }

    public void div(Key key, long num) {
        Long value = getOr(key, 0L);
        set(key, value / num);
    }

    public void mod(Key key, long num) {
        Long value = getOr(key, 0L);
        set(key, value % num);
    }

    @SafeVarargs
    public final long sum(Key... keys) {
        long sum = 0;
        for (Key key : keys) {
            Long v = getOr(key, 0L);
            sum += v;
        }
        return sum;
    }
}
